﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI;

/// <summary>
/// Summary description for TimeInputControl
/// </summary>
namespace UTS.Controls
{
    [
        DefaultProperty("TimeValue"),
        ToolboxData("<{0}:TimeInput runat=\"server\"> </{0}:TimeInput>")
    ]
    public class TimeInputControl : TextBox
    {

        public TimeInputControl()
        {

        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.MaxLength = 5;
        }

        private TimeSpan timeValue;

        public TimeSpan TimeValue
        {
            get 
            { 
                timeValue = TimeSpan.Parse(TimeUtils.adjustTimeString(this.Text)); 
                return timeValue; 
            }
            set 
            { 
                timeValue = value; 
                displayTimeValue(); 
            }
        }

        private void displayTimeValue()
        {
            this.Text = TimeUtils.convertTimespan(timeValue);
        }
    }
}